const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer();
server.on('request', (req, rep) => {
    const url = req.url;
    fs.readFile(path.join(__dirname, url), 'utf-8', (error, data) => {
        if (error == null) {

            rep.setHeader('Content-Type', 'text/html;charset=utf-8;');
            rep.end(data);
        } else {
            rep.setHeader('Content-Type', 'text/html;charset=utf-8;');
            rep.end('读取文件出错!');
        }
    });
})

server.listen(80, () => {
    console.log('server running is at http://127.0.0.1');
});